<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-16 16:17:49
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-04-26 16:35:06
 * @FilePath: \vprisk10.14\src\components\vprisk-grid\vpCol.vue
 * @Description: 表格列组件封装丰富功能，集成el-table-column属性和方法
 注：目前不支持使用slot-scope,若要使用个性化模板，请使用el-table-column
-->
<template>
  <div>
    <el-table-column
      v-bind="{ ...$props, ...$attrs }"
      :show-overflow-tooltip="true"
      v-on="$listeners"
      :formatter="formate"
    >
    <slot></slot>
    </el-table-column>
  </div>
</template>

<script>
import moment from "moment";
export default {
  props: {
    dateFormate: String,
    dictFormate: String,
    diyFormat: Boolean,
    diyFormater: Function
  },
  data() {
    return {
      dictList: []
    };
  },
  mounted() {
    this.getDict();
  },
  methods: {
    getDict() {
      if (this.dictFormate) {
        this.$getDict(this.dictFormate).then(res => {
          if (res.code == 200) {
            this.dictList = res.datas;
          }
        });
      }
    },
    // 各种格式化
    formate(row,column,cellValue,index) {
      let data = eval("row." + this.$attrs.prop);
      // 日期格式化
      if (this.dateFormate) {
        console.log("??", this.dateFormate);
        return moment(data).format(this.dateFormate);
      }
      // 字典翻译
      else if (this.dictFormate) {
        return this.$getLabel(data, this.dictList);
      }
      // 自定义翻译函数
      else if (this.diyFormat) {
        return this.diyFormater(row,column,cellValue,index);
        //不格式化
      } else {
        return data;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
</style>